﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.InvMovementServiceRef;

    public class InvMovementServiceClientProxy : BasePage
    {
        public string AllocateMovement(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.AllocateMovement(movementID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteMovement(List<string> IDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.DeleteMovement(IDS, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteMovementDetail(string movementID, List<string> LineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.DeleteMovementDetail(movementID, LineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public MovementDetailInfo GetAllMovementDetailByID(string movementID, string lineId)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            MovementDetailInfo movementDetailInfo = null;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                movementDetailInfo = client.GetAllMovementDetailByID(movementID, lineId, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return movementDetailInfo;
        }

        public static InvMovementServiceClientProxy GetInstance()
        {
            return new InvMovementServiceClientProxy();
        }

        public DataSet GetMovementAllInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                ds = client.GetMovementAllInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public MovementInfo GetMovementInfoByID(string transID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            MovementInfo movementInfo = null;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                movementInfo = client.GetMovementInfoByID(transID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return movementInfo;
        }

        public DataSet GetMovementInfoByQueryEntity(MovementQueryEntity movementQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                ds = client.GetMovementInfoByQueryEntity(movementQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertMovement(MovementInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.InsertMovement(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertMovementDetail(MovementDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.InsertMovementDetail(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string MovementClose(List<string> movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.MovementClose(movementID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string MovementConfirm(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.MovementConfirm(movementID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string RevertAllocateMovement(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.RevertAllocateMovement(movementID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateMovement(MovementInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.UpdateMovement(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateMovementDetail(MovementDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService");
            try
            {
                result = client.UpdateMovementDetail(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

